/*
 * This file is part of the Code::Blocks IDE and licensed under the GNU Lesser General Public License, version 3
 * http://www.gnu.org/licenses/lgpl-3.0.html
 *
 * $Revision: 8300 $
 * $Id: cbexception.cpp 8300 2012-08-31 11:35:40Z jenslody $
 * $HeadURL: http://svn.code.sf.net/p/codeblocks/code/branches/release-17.xx/src/sdk/cbexception.cpp $
 */

#include "sdk_precomp.h"

#ifndef CB_PRECOMP
    #include "cbexception.h"
    #include "globals.h"
    #include "configmanager.h"
    #include <wx/log.h> // for wxSafeShowMessage()
#endif

#include <wx/intl.h>

cbException::cbException(const wxString& msg, const wxString& file, int line)
  : Message(msg),
    File(file),
    Line(line)
{}

cbException::~cbException()
{}


void cbException::ShowErrorMessage(bool safe)
{
    wxString gccvers;
#ifdef __GNUC__
    gccvers.Printf(wxT("gcc %d.%d.%d"), __GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__);
#endif

    wxString title = wxT("异常");
    wxString err;
    err.Printf(wxT("已引发异常!\n"
                 "应用程序在第%d行的%s处遇到错误.\n"
                 "错误消息是:%s\n"
                 "Code::Blocks 修订版本 %u (%s, 构建: %s %s)"),
               Line,File.wx_str(),  Message.wx_str(),
               ConfigManager::GetRevisionNumber(), gccvers.wx_str(),
               wxT(__DATE__), wxT(__TIME__));

    if (safe) {wxSafeShowMessage(title, err);}else{cbMessageBox(err, title, wxICON_ERROR);}
}
